﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EXAM
{
    public partial class LearnLog : System.Web.UI.Page
    {
        string sErr = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["id"] != null)
                {
                    try
                    {
                        BUS.GadgetItemsControl ctr = new BUS.GadgetItemsControl();
                        DTO.GadgetItemsInfo inf = ctr.Get(Convert.ToInt32(Request["id"].ToString()), ref sErr);

                        if (sErr != "")
                            Response.Write(sErr);
                        else
                        {
                            DTO.UserInfo infUser = Session["UserGuest"] as DTO.UserInfo;
                            BUS.LearnLogControl learnCtr = new BUS.LearnLogControl();
                            DTO.LearnLogInfo learnIng = new DTO.LearnLogInfo(-1, infUser.ID, inf.ID, DateTime.Now, inf.Name);
                            learnCtr.Add(learnIng, ref sErr);
                            Response.Redirect(inf.Link);
                        }
                    }
                    catch (Exception ex) { Response.Write(ex.Message); }
                }
            }
        }
    }
}
